package com.dlc.yunguang.adapter;

import android.content.res.Resources;
import android.graphics.Color;
import android.widget.TextView;

import com.dlc.commonlibrary.adapter.BaseRecyclerAdapter;
import com.dlc.commonlibrary.widget.CommonItemView;
import com.dlc.yunguang.base.Constants;
import com.dlc.yunguang.net.bean.RFIDBean;
import com.dlc.yunguang.R;

/**
 * Created by John on 2017/7/21.
 */

public class ProductAbnormalAdapter extends BaseRecyclerAdapter<RFIDBean.DataBean.ListBean> {

    @Override
    public int getItemViewType(int position) {
        return getItem(position).getLevel();
    }

    @Override
    public int getItemLayoutId(int viewType) {
        return viewType == 0 ? R.layout.item_product_abnormal_0 : R.layout.item_product_abnormal_1;
    }

    @Override
    public void onBindViewHolder(CommonHolder holder, int position) {

        RFIDBean.DataBean.ListBean item = getItem(position);
        if (item.getLevel() == Constants.ITEM_LEVEL.LEVEL_0) {
            bindHead(holder, item);
        } else if (item.getLevel() == Constants.ITEM_LEVEL.LEVEL_1) {
            bindItem(holder,item);
        }
    }

    private void bindHead(CommonHolder holder, RFIDBean.DataBean.ListBean head) {

        CommonItemView view = holder.getView(R.id.civ_head);

        Resources resources = holder.getContext().getResources();

        switch (head.getCategory_id()) {
            case Constants.PRODUCT_TYPE.TOWEL:
                view.setLabelImage(R.mipmap.ic_towel);
                view.setLabel(resources.getString(R.string.towel));
                break;
            case Constants.PRODUCT_TYPE.SHEET:
                view.setLabelImage(R.mipmap.ic_sheet);
                view.setLabel(resources.getString(R.string.sheet));
                break;
            case Constants.PRODUCT_TYPE.BEDDING:
                view.setLabelImage(R.mipmap.ic_message_02);
                view.setLabel(resources.getString(R.string.bedding));
                break;
        }
    }

    private void bindItem(CommonHolder holder,  RFIDBean.DataBean.ListBean item) {
       // holder.setText(R.id.tv_rfid, item.getCardno());
        holder.setText(R.id.tv_name, item.getTitle());
        holder.setText(R.id.tv_spec, item.getSpec());
        holder.setText(R.id.tv_where, item.getWarehouse());
        TextView tv_rfid = holder.getView(R.id.tv_rfid);
        if (item.state == 0){
            tv_rfid.setTextColor(Color.parseColor("#333333"));
        }else {
            tv_rfid.setTextColor(Color.parseColor("#FF6666"));
        }
        tv_rfid.setText( item.getCardno());
    }
}
